<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <title>采集</title>
    <style type="text/css">
        body {  background: #eee; }
        #import { margin: 0 5%; width: 90%; }
        input { padding: 5px 2%; width: 96%; border: 1px solid #cccccc; }
        textarea { padding: 5px 2%; width: 96%; height: 100px; border: 1px solid #cccccc; resize: none; }
        table { margin: 10px 5%; width: 90%; }
        th { padding: 10px; background: #333; color: #ccc; }
        td { padding: 10px; border: 1px solid #eee; background: #e0e0e0; text-align: center; }
    </style>
</head>
<body>
    <div id="import">
        <p>下面导入JSON：<a href="javascript:;" onclick="toimport();">点击导入</a></p>
        <input type="text" id="unitId" placeholder="商铺编号" value="106A"/><br/>
        <textarea id="imbody" placeholder="参数体">{
"TurnoverNo":"106A,20160901",
"Amount":300.00
}_[{
"TurnoverNo":"106A,20160901",
"Item":"商品名称",
"Price":30.00
},{
"TurnoverNo":"106A,20160901",
"Item":"商品名称",
"Price":20.00
}]_[{
"TurnoverNo":"106A,20160901",
"PaymentReceiveMethodId":1,
"Amount":300.00
}]</textarea><br/>
    </div>

    <table>
        <thead>
        <tr>
            <th>商铺编号</th>
            <th>销售主体</th>
            <th>销售明细</th>
            <th>销售付款</th>
            <th>导入时间</th>
        </tr>
        </thead>
        <tr>
            <td>商铺编号</td>
            <td>销售主体</td>
            <td>销售明细</td>
            <td>销售付款</td>
            <td>导入时间</td>
        </tr>
        <tbody>
        </tbody>
    </table>

    <span id="pop"></span>
</body>
</html>


<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="view.js"></script>
<script type="text/javascript">
    (function(){
        getIndex();
    })();
    function getIndex(){
        $.ajax({
            type: 'post',
            url: apiDomain + 'index',
            data: {},
            success: function (res) {
                res = JSON.parse(res);
                console.log(res);
                if (res.Code < 0) {
                    msgPop({msg: res.Message}); return
                }
                var d = res.Data;
                console.log(d);
                var h = '', i = 0;
                for (; i < d.length; i ++) {
                    h += '<tr>';
                    h += '<td>' + d[i].unitId + '</td>';
                    h += '<td>' + d[i].saleBody + '</td>';
                    h += '<td>' + d[i].saleDetail + '</td>';
                    h += '<td>' + d[i].salePay + '</td>';
                    h += '<td>' + d[i].addtime + '</td>';
                    h += '</tr>';
                }
                $('tbody').html(h);
            },
            error: function (err) {
                console.log(err);
            }
        });
    }
    function toimport(){
        var unitId = $('#unitId').val();
        var formData = {
            body: $('#imbody').val(),
        };
        $.ajax({
            type: 'post',
            url: apiDomain + 'Import?unitId=' + unitId,
            data: formData,
            success: function (res) {
                console.log(res);
                if (res.code < 0) {
                    msgPop({msg: res.msg}); return
                }
                msgPop({msg: '成功'});
                setTimeout(function(){
                    window.location.href = '';
                }, 500);
            },
            error: function (err) {
                console.log(err);
            }
        });
    }
</script>